<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>供应商监所对应表</title>
    <th:block th:include="~{common/common::commonHead}"/>
</head>
<body>
<div class="page-body">
    <div class="panel panel-primary shiny">
        <div class="panel-heading bg-blue">
            供应商监所对应表
        </div>
        <div class="widget-body grid-table">
            <div class="toolbar">
                <div class="fl-left">
                    <button data-menu-id="080301" data-click="add('manage/relationSupplierPrisonAdd.html','relationSupplierPrison')" class="btn btn-blue shiny">新增对应关系</button>
                    <button data-menu-id="080302" onclick="pass();" class="btn btn-blue shiny">审核通过</button>
                    <button data-menu-id="080302" onclick="fail();" class="btn btn-blue shiny">审核不通过</button>
                </div>
                <div class="toolbar-right">
                    <div class="fl-right">
                        <div class="btn-group" role="group">
                            <button data-click="toggleFilter()" class="btn btn-default text-center">
                                <i class="fa fa-filter fa-fw"></i>
                            </button>
                            <button data-click="refresh('relationSupplierPrison')" class="btn btn-default">
                                <i class="fa fa-refresh fa-fw"></i>
                            </button>
                            <button data-click="download('relationSupplierPrison')" class="btn btn-default">
                                <i class="fa fa-download fa-fw"></i>
                            </button>
                        </div>
                    </div>
                </div>
            </div>
            <div id="relationSupplierPrison"></div>
            <form class="filter search-content form-horizontal" data-width="650" role="form">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="col-xs-4 control-label"> 供应商名称 </label>
                        <div class="col-xs-8">
                            <div class="iconic-input right">
                                <select name="supplierName" class="form-control spinner" data-url="org/listSupplierRelation" data-value="-1" data-value-field="id" data-text-field="orgName" >
                                    <option value="-1">全部</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="col-xs-4 control-label"> 监所名称 </label>
                        <div class="col-xs-8">
                            <div class="iconic-input right">
                                <select name="prisonsName" class="form-control spinner" data-url="org/listPrisonRelation" data-value="-1" data-value-field="id" data-text-field="orgName" >
                                    <option value="-1">全部</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-xs-12">
                    <button type="button" data-click="hideFilter()" class="btn btn-default pull-right">取消</button>
                    <button type="button" data-click="submitFilter('relationSupplierPrison')" class="btn btn-primary pull-right">确定</button>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
</html>
<script>
    $(function () {
        $("#relationSupplierPrison").gridTable({
            url: "relationSupplierPrison/pageRelationSupplierPrison",
                columns: [
                {title: "供应商名称", field: "supplierName"},
                {title: "监所名称", field: "prisonsName"},
                {title: "关联关系", field: "status",format:toStatus},
                {title: "过期时间", field: "overDue"},
                {title: "创建时间", field: "createTime"}

            ],
            idField: "id",
            showControl:false
        });
    });
    //判断状态
    function toStatus(status) {
        switch (status) {
            case '1':
                return "<span class='label label-success'>审核通过</span>";
            case '0':
                return "<span class='label label-default'>待审核</span>";
            case '9':
                return "<span class='label label-default'>审核失败</span>";
            case '99':
                return "<span class='label label-default'>过期</span>";
            default:
                return status;
        }
    }
    //审核通过
    function pass(){
        var gridTable =$$selection.get("gridTable","relationSupplierPrison");
        var selectedRows = gridTable.getSelectedRows();
        if(selectedRows.length === 0) {
            $.error("未选择任何数据");
            return;
        }
            if (selectedRows.length > 1) {
                $.error("只允许选择一条数据");
                return false
            }
            selectedRows.forEach(function (row) {
                row.setStyleEdit();
            });
            $.confirm({
                title: "审核通过确认",
                icon: "fa fa-question-circle-o",
                content: "<p>确认让选中的 <span class='text-danger'>" + selectedRows.length + "</span> 条数据通过吗？</p>",
                theme: "modern",
                type: "orange",
                buttons: {
                    ok: {
                        text: "审核",
                        btnClass: "btn-danger",
                        action: function () {
                            var arr={};
                            var prisonId;
                            var supplierId;
                            selectedRows.forEach(function (row) {
                                 prisonId= row.getData().prisonId;
                                 supplierId = row.getData().supplierId;
                            });
                            arr.prisonId= prisonId;
                            arr.supplierId=supplierId;
                            var json = JSON.stringify(arr);
                            var scb = function () {
                                $.success("审核通过：通过了" + selectedRows.length + "条数据");
                                gridTable.reloadData();
                            };
                            var ecb = function (error) {
                                $.error(error.msg);
                                selectedRows.forEach(function (row) {
                                    row.unsetStyleEdit();
                                });

                            };
                            $.doAjax("relationSupplierPrison/auditRelationSupplierPrison", {"relationSupplierPrison": json}, scb, ecb);
                        }
                    },
                    cancel: {
                        text: "取消",
                        btnClass: "btn-success",
                        action: function () {
                            selectedRows.forEach(function (row) {
                                row.unsetStyleEdit();
                            });
                        }
                    }
                }
            });
        }
        //审核不通过
    function fail(){
        var gridTable =$$selection.get("gridTable","relationSupplierPrison");
        var selectedRows = gridTable.getSelectedRows();
        if(selectedRows.length === 0) {
            $.error("未选择任何数据");
            return;
        }
        if (selectedRows.length > 1) {
            $.error("只允许选择一条数据");
            return false
        }
        selectedRows.forEach(function (row) {
            row.setStyleEdit();
        });
        $.confirm({
            title: "审核不通过确认",
            icon: "fa fa-question-circle-o",
            content: "<p>确认让选中的 <span class='text-danger'>" + selectedRows.length + "</span> 条数据不通过吗？</p>",
            theme: "modern",
            type: "orange",
            buttons: {
                ok: {
                    text: "审核不通过",
                    btnClass: "btn-danger",
                    action: function () {
                        var arr={};
                        var prisonId;
                        var supplierId;
                        selectedRows.forEach(function (row) {
                            prisonId= row.getData().prisonId;
                            supplierId = row.getData().supplierId;
                        });
                        arr.prisonId= prisonId;
                        arr.supplierId=supplierId;
                        var json = JSON.stringify(arr);
                        var scb = function () {
                            $.success("审核未通过：" + selectedRows.length + "条数据");
                            gridTable.reloadData();
                        };
                        var ecb = function (error) {
                            $.error(error.msg);
                            selectedRows.forEach(function (row) {
                                row.unsetStyleEdit();
                            });

                        };
                        $.doAjax("relationSupplierPrison/failRelationSupplierPrison", {"relationSupplierPrison": json}, scb, ecb);
                    }
                },
                cancel: {
                    text: "取消",
                    btnClass: "btn-success",
                    action: function () {
                        selectedRows.forEach(function (row) {
                            row.unsetStyleEdit();
                        });
                    }
                }
            }
        });
    }

</script>
